package cn.qhuan.modules.controller;

import cn.qhuan.modules.dtos.ArtistAbbDto;
import cn.qhuan.modules.dtos.ArtistAuthDto;
import cn.qhuan.modules.dtos.ArtistDto;
import cn.qhuan.modules.entity.Artist;
import cn.qhuan.modules.service.IArtistService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.UUID;

/**
* @Description: 艺术家表
* @Author: 司翔宇
* @Date:   2020-12-28
* @Version: V1.0
*/
@Api(tags="艺术家表")
@RestController
@RequestMapping("/artist")
@Slf4j
public class ArtistController extends JeecgController<Artist, IArtistService> {
   @Autowired
   private IArtistService artistService;

    /**
     * 条件分页查询
     *
     * @param dto
     * @return
     */
    @AutoLog(value = "艺术家表-条件分页查询")
    @ApiOperation(value = "艺术家表-条件分页查询", notes = "艺术家表-条件分页查询")
    @PostMapping("/list")
    public Result findByCondition(@RequestBody ArtistDto dto) {
        return artistService.findByCondition(dto);
    }

   /**
    *   添加
    *
    * @param qhArtist
    * @return
    */
   @AutoLog(value = "艺术家表-添加")
   @ApiOperation(value="艺术家表-添加", notes="艺术家表-添加")
   @PostMapping(value = "/add")
   public Result<?> add(@RequestBody Artist qhArtist) {
       artistService.save(qhArtist);
       return Result.OK("添加成功！");
   }

   /**
    *  编辑
    *
    * @param qhArtist
    * @return
    */
   @AutoLog(value = "艺术家表-编辑")
   @ApiOperation(value="艺术家表-编辑", notes="艺术家表-编辑")
   @PutMapping(value = "/edit")
   public Result<?> edit(@RequestBody Artist qhArtist) {
       artistService.updateById(qhArtist);
       return Result.OK("编辑成功!");
   }

   /**
    *   通过id删除
    *
    * @param id
    * @return
    */
   @AutoLog(value = "艺术家表-通过id删除")
   @ApiOperation(value="艺术家表-通过id删除", notes="艺术家表-通过id删除")
   @DeleteMapping(value = "/delete")
   public Result<?> delete(@RequestParam(name="id",required=true) String id) {
       artistService.removeById(id);
       return Result.OK("删除成功!");
   }

   /**
    *  批量删除
    *
    * @param ids
    * @return
    */
   @AutoLog(value = "艺术家表-批量删除")
   @ApiOperation(value="艺术家表-批量删除", notes="艺术家表-批量删除")
   @DeleteMapping(value = "/deleteBatch")
   public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
       this.artistService.removeByIds(Arrays.asList(ids.split(",")));
       return Result.OK("批量删除成功!");
   }

   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   @AutoLog(value = "艺术家表-通过id查询")
   @ApiOperation(value="艺术家表-通过id查询", notes="艺术家表-通过id查询")
   @GetMapping(value = "/queryById")
   public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
       Artist qhArtist = artistService.getById(id);
       if(qhArtist==null) {
           return Result.error("未找到对应数据");
       }
       return Result.OK(qhArtist);
   }

   /**
   * 导出excel
   *
   * @param request
   * @param qhArtist
   */
   @RequestMapping(value = "/exportXls")
   public ModelAndView exportXls(HttpServletRequest request, Artist qhArtist) {
       return super.exportXls(request, qhArtist, Artist.class, "艺术家表");
   }

   /**
     * 通过excel导入数据
   *
   * @param request
   * @param response
   * @return
   */
   @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
   public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
       return super.importExcel(request, response, Artist.class);
   }

    /**
     * 审核操作
     * @param artistAuthDto
     * @return
     */
    @AutoLog(value = "艺术家表-审核操作")
    @ApiOperation(value = "艺术家表-审核操作", notes = "艺术家表-审核操作")
    @PostMapping("/auth")
    public Result authPass(@RequestBody ArtistAuthDto artistAuthDto,Integer type){
        return artistService.updateStatus(artistAuthDto,type);
    }


    /**
     * 通过26字母查询艺术家
     * @param dto
     * @param
     * @return
     */
    @AutoLog(value = "艺术家表-通过26字母查询艺术家")
    @ApiOperation(value="艺术家表-通过26字母查询艺术家", notes="艺术家表-通过26字母查询艺术家")
    @PostMapping(value = "/queryByAbbreviation")
    public Result<?> queryByAbbreviation(@RequestBody ArtistAbbDto dto){
        return artistService.findByAbbreviation(dto);
    }
    /**
     *  艺术家主页展示作品
     *
     * @param dto
     * @return
     */
    @AutoLog(value = "艺术家表-展示作品")
    @ApiOperation(value="艺术家表-展示作品", notes="艺术家表-展示作品")
    @PostMapping(value = "/findWorksByArtistId")
    public Result<?> findWorksByArtistId(@RequestBody ArtistDto dto) {
        return artistService.queryWorksByArtistId(dto);
    }
    /**
     *  艺术家主页通过展厅id查询相关的作品
     *
     * @param artistId
     * @return
     */
    @AutoLog(value = "艺术家表-在线展厅展示作品")
    @ApiOperation(value="艺术家表-在线展厅展示作品", notes="艺术家表-在线展厅展示作品")
    @GetMapping(value = "/loadWorksByExhiId")
    public Result<?> loadWorksByExhiId(@RequestParam (name = "artistId", required = true)String artistId,String exhiId) {
        return artistService.queryWorksByEhxhiOnArtist(artistId,exhiId);
    }
    /**
     *  艺术家主页管理显示作品数量
     *
     * @param artistId
     * @return
     */
    @AutoLog(value = "艺术家表-显示作品数量")
    @ApiOperation(value="艺术家表-显示作品数量", notes="艺术家表-显示作品数量")
    @GetMapping(value = "/queryWorksCountByArtistId")
    public Result<?> queryWorksCountByArtistId(@RequestParam (name = "artistId", required = true)String artistId) {
        return artistService.queryWorksCountOnArtist(artistId);
    }

    /**
     *  艺术家主页管理显示文章数量
     *
     * @param artistId
     * @return
     */
    @AutoLog(value = "艺术家表-显示文章数量")
    @ApiOperation(value="艺术家表-显示文章数量", notes="艺术家表-显示文章数量")
    @GetMapping(value = "/queryDocumentCountByArtistId")
    public Result<?> queryDocumentCountByArtistId(@RequestParam (name = "artistId", required = true)String artistId) {
        return artistService.queryDocumentCountOnArtist(artistId);
    }
}
